<?php
namespace Admin\Controller;
use think\Controller;
use Think\Verify;

class LoginController extends Controller {

    public function login() {
        if(IS_POST) {
            $verify = new Verify();
            if($verify->check(I('post.captcha', '', 'trim'))) {
                $data['admin_name'] = i('post.admin_user');
                $data['password'] = I('post.admin_psd', '', 'md5');
                $row = M('manager')->where($data)->find();
                if($row) {
                    session('admin_id', $row['admin_id']);
                    $this->redirect('Manager/index');
                }
                else {
                    $this->error('用户名或密码错误', U('login'), 3);
                }
            }
            else {
                $this->error('验证码错误', U('login'), 3);
            }
        }
        $this->display();
    }

    public function verifyImg() {
        $config = array(
            'imageH'    =>  40,                   // 验证码图片高度
            'imageW'    =>  120,                  // 验证码图片宽度
            'length'    =>  4,                    // 验证码位数
            'fontttf'   =>  '4.ttf',              // 验证码字体
            'fontSize'  =>  16,              // 验证码字体大小(px)
        );
        $verify = new Verify($config);
        $verify->entry();
    }
}